/*
* $Id: AddHousingOperation.cpp 336 2011-09-28 06:06:36Z volok-aleksej@yandex.ru $
*
* Copyright 2009-2011 by Volokitin Aleksey
* All rights reserved
*
*/
#include "Common/include.h"
#include "AddHousingOperation.h"
#include "Threads/ComReader.h"
#include "Database/TransactManager.h"
#include "Database/Tables/HousingsTable.h"

CAddHousingOperation::CAddHousingOperation(CTransactManager* pManager)
: m_pManager(pManager){}
CAddHousingOperation::~CAddHousingOperation(){}

std::tstring CAddHousingOperation::ExecuteOperation(IDatabase* pDatabase, IReader* pReader){
	int size;
	pReader->ReadInt(size);
	int lenData = 0;
	CHousingsTable housings;
	int idHousing;
	lenData = pReader->ReadInt(idHousing);
	lenData += pReader->ReadUTF(housings.m_content.s_strName);
	std::tstring strNameHousing = housings.m_content.s_strName;
	int idFamily;
	lenData += pReader->ReadInt(idFamily);
	if(idFamily != 0)
		idFamily = m_pManager->GetRealId(CTransactManager::ID(CTransactManager::FAMILY, idFamily));
	housings.m_content.s_nIdFamily = idFamily;
	lenData += pReader->ReadInt(housings.m_content.s_nType);
	lenData += pReader->ReadInt(housings.m_content.s_nFrames);
	lenData += pReader->ReadBool(housings.m_content.s_bDelete);
	housings.SetValue(pDatabase);
	m_pManager->AddIDMap(CTransactManager::ID(CTransactManager::HOUSING, idHousing),
						housings.m_content.s_nId);
	std::tstring strLog = ILanguageManager::GetLanguageManager()->GetString(ADD_HOUSING_LOG_ID);
	return strLog + _T("") + strNameHousing;
}

void CAddHousingOperation::Free(){
	delete this;
}
